<%@page import="Session.ClientSessionLocal"%>
<%@page import="Session.ContratHabitatSessionLocal"%>

<%@page import="javax.servlet.http.HttpSession"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Connexion | Assur'Tout</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.4.2.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_400.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_700.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_600.font.js"></script>


</head>
<body id="page2">
<!-- START PAGE SOURCE -->
<div class="main">
  <header>
    <div class="wrapper">
      <h1><a href="index.html" id="logo">Assur'Tout</a></h1>

    </div>
    <nav>
      <ul id="menu">
        <li class="alpha"><a href="index.jsp"><span><span>Accueil</span></span></a></li>
        <li><a href="inscription_info.jsp"><span><span>Inscription</span></span> </a></li>
        <li><a href="connexion.jsp"><span><span>Mon compte</span></span></a></li>
        <li class="omega"><a href="contact.jsp"><span><span>Contact courtier</span></span></a></li>
      </ul>
    </nav>
  </header>
  
    <%@page import="Session.SinistreHabitatSessionLocal"%>
    <%@page import="javax.naming.InitialContext" %>
    <%@page import="javax.ejb.EJBException" %>
    <%
    String adresse = (String) session.getAttribute("adresse");
    String numcontrat = (String) session.getAttribute("num_contrat_habitat");
    request.setAttribute("contrat", numcontrat);
    String numero = request.getParameter("numero");
    String day = request.getParameter("day");
    String description = request.getParameter("description");
    String incident = request.getParameter("type");
    
    
    InitialContext ic = new InitialContext();
    
    if ( numero == null || day.equals("") || description.equals("")) {
        if (request.getMethod().equals("POST")) { // Form is partially filled-in
    %>
    <script>alert("Champs vides !");</script>
    <%    
        }
    } else {  
        try{
            //test si le contrat existe
            ContratHabitatSessionLocal test = (ContratHabitatSessionLocal) ic.lookup("java:comp/env/ContratHabitatSessionLocal");
            if(test.testExistence(numero)){
                //enregistrement du sinistre
                SinistreHabitatSessionLocal shsl = (SinistreHabitatSessionLocal) ic.lookup("java:comp/env/SinistreHabitatSessionLocal");
                if(shsl.declarer(numero, day, adresse, description, incident)){
                    session.setAttribute("sinistre", "Votre sinistre a été enregistré, il sera analysé par un de nos rédacteurs.");
                    response.sendRedirect("mon_compte.jsp");
                }
            }else{%>
            <script>alert("Contrat inexistant !");</script>
           <% }
        }catch (EJBException e){
    %>
            <p> error <%=e.getLocalizedMessage()%></p>
            <%
        }
    }
        
    %>
    
  
  <section id="content">
    <div class="wrapper">
      <div class="pad">
          <article class="col1">
            <h2>Sinistre Habitat</h2>
          </article>
      </div>
      <div class="box pad_bot1">
        <div class="pad marg_top">
	  <article class="pad">       
             
              <form id="SinistreForm" action="" methode="post">
              <tr>
                  <td><label> Numéro du contrat d'assurance : <%=request.getAttribute("contrat") %></label> 
                  <td><input type="text" value="<%=request.getAttribute("contrat") %>" name="numero" style="display:none"/></td>
	      </tr>
                  <br/> <br/>
              <tr>
		<td><label>Nature : </label>
                <td><input type="radio" value="vol" name="type"/>Vol</td>
                <td><input type="radio" value="incendie" name="type"/>Incendie</td>
                <td><input type="radio" value="degatEau" name="type"/>Dégâts des eaux</td>

	      </tr>
                                    <br/> <br/>

	      <tr>
		<td><label>Date du sinistre : </label></td>
		<td><input type="text" name="day" value="" placeholder="DD/MM/YYYY"/></td>
	      </tr>
                                                      <br/> <br/>


	      <tr>
		<td><label>Lieu du sinistre : </label></td>
		<td><input type="text"  name="adresse" placeholder="Adresse" value="" /></td>
	      </tr>
	                     <br/> <br/>

	      <tr>
		<td><label>Description détaillée : </label></td>
		<td><textarea name="description" value=""></textarea></td>
	      </tr>
                                  <br/> <br/>

              <input type="submit" name="submit" value="Déclaration" class="button">
	    </form>
	  </article>
	</div>
      </div>
    </div>
  </section>
  <footer>
    <div style="clear:both;"></div>
  </footer>
</div>
<script type="text/javascript"> Cufon.now(); </script>
<!-- END PAGE SOURCE -->
</html>
